<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #c1{
            fill:#fac ;
            transition: fill 1s;
        }
        #c1.a{
            fill:#caf;
        }
        #c2{
            fill:#f00 ;
            transition: fill 1s;
        }
        #c2.a{
            fill:#00f;
        }
    </style>
</head>
<body>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" 
    width="500" height="500" style="border:#aaa solid" >
        <g>
            <path d="M0 10 H100 M0 20 H100 M0 30 H100 M0 40 H100 M0 50 H100 M0 60 H100 M0 70 H100 M0 80 H100 M0 90 H100
                    M10 0 V100 M20 0 V100 M30 0 V100 M40 0 V100 M50 0 V100 M60 0 V100 M70 0 V100 M80 0 V100 M90 0 V100" 
            stroke="#aaa" stroke-width=".2" fill="none"/>
            <text x="0" y="3" font-size="3">0</text>
            <text x="8" y="3" font-size="3">10</text>
            <text x="18" y="3" font-size="3">20</text>
            <text x="28" y="3" font-size="3">30</text>
            <text x="38" y="3" font-size="3">40</text>
            <text x="48" y="3" font-size="3">50</text>
            <text x="58" y="3" font-size="3">60</text>
            <text x="68" y="3" font-size="3">70</text>
            <text x="78" y="3" font-size="3">80</text>
            <text x="88" y="3" font-size="3">90</text>
            <text y="11" x="0" font-size="3">10</text>
            <text y="21" x="0" font-size="3">20</text>
            <text y="31" x="0" font-size="3">30</text>
            <text y="41" x="0" font-size="3">40</text>
            <text y="51" x="0" font-size="3">50</text>
            <text y="61" x="0" font-size="3">60</text>
            <text y="71" x="0" font-size="3">70</text>
            <text y="81" x="0" font-size="3">80</text>
            <text y="91" x="0" font-size="3">90</text>
        </g>
        <!-- enter your code -->
        
        <path id="c1" d="M20 50 A30 30 0 0 1 80 50 A30 30 0 0 1 20 50"
             stroke="#888" stroke-width="2"  />

        <path id="c2" d="M65 50 A15 15 0 0 1 35 50 A15 15 0 0 1 65 50"
             stroke="#555" stroke-width="2" />
    </svg>
</body>
</html>
<script>
    const c1 = document.querySelector('#c1');
    const c2 = document.querySelector('#c2');

    //设置虚线及偏移
    const length1 = c1.getTotalLength();
    const length2 = c2.getTotalLength();
    c1.setAttribute('stroke-dasharray',length1) ;
    c1.setAttribute('stroke-dashoffset',length1);
    c2.setAttribute('stroke-dasharray',length2) ;
    c2.setAttribute('stroke-dashoffset',length2);
    

    //动画出现圆周描边,1s 40次完成
    const s1 = length1/40 ;//速度
    const s2 = length2/40 ;
    
    function move(c,s,t,fn){
        setTimeout(()=>{
           let offset = c.getAttribute('stroke-dashoffset'); 
           offset -= s ;
           if(offset <= t){
                c.setAttribute('stroke-dashoffset',t);
                if(fn)
                    fn();
                return ;
           }
           c.setAttribute('stroke-dashoffset',offset) ;
           move(c,s,t,fn);
        },25);
    }

    function loop(){
        
        c1.setAttribute('stroke-dasharray',length1) ;
        c1.setAttribute('stroke-dashoffset',length1);
        c2.setAttribute('stroke-dasharray',length2) ;
        c2.setAttribute('stroke-dashoffset',length2);
        
        move(c1,s1,0,()=>{
            move(c1,s1,-length1);
            c1.classList.toggle('a');
        });
        c1.classList.toggle('a');

        move(c2,s2,0,()=>{
            move(c2,s2,-length2,loop);
            c2.classList.toggle('a');
        });
        c2.classList.toggle('a');
    }
    loop();
    
</script>